/*
 * 文件名:ProduceplanServiceImpl.java
 * 创建时间:2010-10-01
 * 版本:2.0
 * 版权所有:杨涛 walle1027@gmail.com
 */
package com.yangtao.wms.master.produceplan.service.impl;

import com.yangtao.framework.service.BaseService;
import com.yangtao.framework.util.StringHelper;
import com.yangtao.wms.dao.ProducePlanDao;
import com.yangtao.wms.domain.ProducePlan;
import com.yangtao.wms.master.produceplan.service.ProduceplanService;
import com.yangtao.wms.master.produceplan.web.ProduceplanModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 代码生成器 v-2.0
 * @version 2.0
 */
@Service()
public class ProduceplanServiceImpl extends BaseService implements ProduceplanService {

	@Autowired
	protected ProducePlanDao producePlanDao;

	/**
	 * 查询记录，并且分页
	 *
	 * @param model 页面参数
	 */
	@Override
	public ProduceplanModel list(ProduceplanModel model) {
		producePlanDao.findPageByCondition(model.getPage(), model.getCondition());
		return model;
	}

	/**
	 * 取得唯一记录
	 *
	 * @param model 页面参数
	 */
	@Override
	public ProduceplanModel loadProducePlan(ProduceplanModel model) {
		if (StringHelper.isNotEmpty(model.getProducePlan().getId())) {
			model.setProducePlan(producePlanDao.loadForReview(model.getProducePlan().getId()));
		}
		return model;
	}

	/**
	 * 新增记录
	 *
	 * @param model 页面参数
	 */
	@Override
	public ProduceplanModel addProducePlan(ProduceplanModel model) {
		//VO
		ProducePlan producePlanVO = model.getProducePlan();
		//PO
		ProducePlan producePlanPO = new ProducePlan();
		mapper.map(producePlanVO, producePlanPO);
		//保存对象
		producePlanDao.save(producePlanPO);
		//增加保存成功的消息
		model.addInfo("add.success");
		return model;
	}

	/**
	 * 更新记录
	 *
	 * @param model 页面参数
	 */
	@Override
	public ProduceplanModel updateProducePlan(ProduceplanModel model) {
		//VO
		ProducePlan producePlanVO = model.getProducePlan();
		//主键
		String producePlanId = producePlanVO.getId();
		//PO
		ProducePlan producePlanPO = producePlanDao.load(producePlanId);
		//复制页面属性
		mapper.map(producePlanVO, producePlanPO);
		//TODO 增加其他属性
		//TODO 更新关联对象
		//构造关联从对象
		//增加保存成功的消息
		model.addInfo("update.success");
		return model;
	}

	/**
	 * 删除记录
	 *
	 * @param model 页面参数
	 */
	@Override
	public ProduceplanModel deleteProducePlan(ProduceplanModel model) {
		producePlanDao.delete(model.getProducePlan().getId());
		model.addInfo("delete.success");
		return model;
	}
}
